package com.bw.servlet;

import com.bw.dao.EleproDao;
import com.bw.pojo.Elepro;
import lombok.SneakyThrows;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/***************************
 FileAction:

 CreateTime:2022-04-12 11:17
 Author:Aaking-aline
 ****************************/
@WebServlet("/InsertServlet")
public class InsertServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @SneakyThrows
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Elepro elepro = new Elepro();

        BeanUtils.populate(elepro,parameterMap);

        new EleproDao().insertElepro(elepro);

        response.sendRedirect("message.jsp");
    }
}
